package br.com.fiap.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.fiap.dao.ReservaDAO;
import br.com.fiap.entity.Cliente;
import br.com.fiap.entity.Reserva;

public class ReservaDAOImpl extends AbstractDAOImpl<Reserva> implements ReservaDAO {
	
	private static final long serialVersionUID = -8430451185188755546L;
	
	public List<Reserva> findByCliente(final Cliente cliente) {
		
		Session session = this.getHibernateSession();
		
		StringBuilder sql = new StringBuilder();
		
		sql.append(" select r from " + Reserva.class.getCanonicalName() + " r ");
		sql.append(" where r.cliente.id = :idCliente ");
		
		Query query = session.createQuery(sql.toString());
		
		query.setParameter("idCliente", cliente.getId());
		
		List<Reserva> list = query.list();
		
		return list;
		
	}

	@Override
	public Class<Reserva> getEntityClass() {
		return Reserva.class;
	}


}
